home *** CD-ROM | disk | FTP | other *** search
- Path: kettle.magna.com.au!4
- From: techteam@stratem.com.au (Technical Team)
- Newsgroups: comp.lang.c++
- Subject: Borland C++ 4.52 - problems with tellg & ftell
- Date: Thu, 18 Jan 96 15:06:33 GMT
- Organization: Stratem Group
- Message-ID: <4dk2qh$se7@kettle.magna.com.au>
- NNTP-Posting-Host: techteam.magna.com.au
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- PROBLEM WITH istream:: tellg() using Borland C++ 4.52 WIN 32
-
- We have made a function called SkipHash which should test if a line
- is starting with a '#", and if it is, skip the line. The function
- should move the stream pointer to the beginning of the first line not
- starting with '#'. But function istream:: tellg is not always
- returning the correct current position, so function istream::seekg is
- not correctly positioning the file pointer. We have not had the same
- problem running under WIN 16, but we have had the same problem
- using ftell function and file handles under WIN 32.
-
- Has anyone else had problems using tellg or ftell using Borland with
- WIN 32 ?
-
- Code for my function is:
- // Checks for '#' character
- // Goes to the beginning of the first line not starting with '#'
- // If it reaches end of file before this it returns 1
- // If successful returns 0
-
- int SkipHash(ifstream& fstream)
- {
- char szTemp[256];
-
- int a = fstream.tellg();
-
- char ch = fstream.get();
-
- while(ch == '\n' || ch == ' ' || ch == '\t' || ch == '#' ||
- ch == EOF)
- {
- if(ch == EOF)
- return 1;
- else if(ch == '#')
- {
- // Reads line of text
- ReadLine(fstream, szTemp);
- a = fstream.tellg();
- ch = fstream.get();
- }
- else
- {
- a = fstream.tellg();
- ch = fstream.get();
- }
- }
-
- fstream.seekg(a);
- return 0;
- }
-
- Please let me know if you can see anything wrong with this code.
-
- Michael Lang
- Manager Systems Development
-
- P.S I've reposted this article as our email address was incorrectly
- displayed in the last article
-